<template>
  <div class="app-container">
    <div class="change">
      <p>
        <span>单据日期</span>
        <el-date-picker v-model="tempData.purchaseTime" disabled type="date" value-format="yyyy-MM-dd" class="userselect" placeholder="选择日期"></el-date-picker>
      </p>
      <p>
        <span>供应商</span>
        <el-select v-model="tempData.supplierId" disabled placeholder="请选择供应商" class="userselect">
          <el-option
            v-for="item in gongying"
            :key="item.supplierId"
            :label="item.supplierName"
            :value="item.supplierName"
          ></el-option>
        </el-select>
      </p>
      <p>
        <span>采购部门</span>
        <el-select v-model="tempData.departments" disabled placeholder="请选择单位分类" class="userselect">
          <el-option
            v-for="item in ifydata"
            :key="item.id"
            :label="item.departments"
            :value="item.departments"
          ></el-option>
        </el-select>
      </p>
      <p>
        <span>采购员</span>
        <input v-model="tempData.operator" disabled type="text" placeholder="请选择采购员" />
      </p>
      <p>
        <span>采购类型</span>
        <input v-model="tempData.invoices" disabled type="text" placeholder="请输入采购类型" />
      </p>
      <p>
        <span>发运方式</span>
        <input v-model="tempData.transports" disabled type="text" placeholder="请输入发运方式" />
      </p>
    </div>
    <!-- 产品数据 -->
    <div class="zd3-btm">
      <el-table :data="proData" :show-header="true" style="width: 100%;border-radius: 8px;">
        <el-table-column type="index" label="序号" align="center" width="80" />
        <el-table-column align="center" label="名称" width="150">
          <template slot-scope="scope">
            <input v-model="scope.row.commodityName" :class="scope.row.ischeck ? 'inps-active' : 'inps'"  type="text" :disabled="!scope.row.ischeck"/>
          </template>
        </el-table-column>
        <el-table-column align="center" label="频率" width="150">
          <template slot-scope="scope">
            <input v-model="scope.row.frequencys" :class="scope.row.ischeck ? 'inps-active' : 'inps'"  type="text" :disabled="!scope.row.ischeck"/>
          </template>
        </el-table-column>
        <el-table-column align="center" label="润滑方式" width="150">
          <template slot-scope="scope">
            <input v-model="scope.row.lubrication" :class="scope.row.ischeck ? 'inps-active' : 'inps'"  type="text" :disabled="!scope.row.ischeck"/>
          </template>
        </el-table-column>
        <el-table-column align="center" label="数量" width="150">
          <template slot-scope="scope">
            <input v-model="scope.row.num" :class="scope.row.ischeck ? 'inps-active' : 'inps'"  type="text" :disabled="!scope.row.ischeck"/>
          </template>
        </el-table-column>
        <el-table-column align="center" label="参数" width="150">
          <template slot-scope="scope">
            <input v-model="scope.row.parameters" :class="scope.row.ischeck ? 'inps-active' : 'inps'"  type="text" :disabled="!scope.row.ischeck"/>
          </template>
        </el-table-column>
				<el-table-column align="center" label="单重" width="150">
				  <template slot-scope="scope">
				    <input v-model="scope.row.pieceWeight" :class="scope.row.ischeck ? 'inps-active' : 'inps'"  type="text" :disabled="!scope.row.ischeck"/>
				  </template>
				</el-table-column>
				<el-table-column align="center" label="功率" width="150">
				  <template slot-scope="scope">
				    <input v-model="scope.row.powers" :class="scope.row.ischeck ? 'inps-active' : 'inps'"  type="text" :disabled="!scope.row.ischeck"/>
				  </template>
				</el-table-column>
				<el-table-column align="center" label="转/分" width="150">
				  <template slot-scope="scope">
				    <input v-model="scope.row.revolutionsPerMinute" :class="scope.row.ischeck ? 'inps-active' : 'inps'"  type="text" :disabled="!scope.row.ischeck"/>
				  </template>
				</el-table-column>
				<el-table-column align="center" label="材质" width="150">
				  <template slot-scope="scope">
				    <input v-model="scope.row.texture" :class="scope.row.ischeck ? 'inps-active' : 'inps'"  type="text" :disabled="!scope.row.ischeck"/>
				  </template>
				</el-table-column>
        <el-table-column align="center" label="单价" width="150">
          <template slot-scope="scope">
            <input v-model="scope.row.unitPrice" :class="scope.row.ischeck ? 'inps-active' : 'inps'"  type="text" :disabled="!scope.row.ischeck"/>
          </template>
        </el-table-column>
        <el-table-column align="center" label="采购金额" width="150">
          <template slot-scope="scope">
            <input v-model="scope.row.unitPrice*scope.row.num" :class="scope.row.ischeck ? 'inps-active' : 'inps'"  type="text" :disabled="!scope.row.ischeck"/>
          </template>
        </el-table-column>
      </el-table>
			<div class="submits" v-if="!islook">
				<div class="save" @click="saveOrder">返回</div>
			</div>
    </div>
  </div>
</template>
<script>
import { getUser,getBumen } from '@/api/people'
import { getGongying,addCaigou,updateCaigouOrPro } from '@/api/caigou'
// import { getCangku,productOneClass,withIdGetPro } from '@/api/cangku'
import { inStock } from '@/api/cangku'
export default {
  data() {
    return {
      radio: "1",
			total: 1,
      value: '',
      tableData: [],
      oneClassify: [],   //一级分类
      twoClassify: [],
      tempData: {
        departments: "",  //部门
        invoices: "",    //发票
        operator: "",    //操作人员
        status: '1',
        purchaseTime: '',   //订单时间
        supplierId: '',     //供应商
        //purchasetype: '1',   //采购类型
        // companyName: "",
      },
			options: [{
				label: '选项1',
				value: 1
			},
			{
				label: '选项2',
				value: 2
      }],
      ifydata: [{
        id: 0,
        departments: '全部',
        value: ''
			}],   //部门列表
      bumen: '',     //部门值
      buyerList: {},
      gongying: [], //供应商管理
      gys:'', //供应商选择值
			proDeail: [],  //商品列表
      peopleData: [],  //人员列表
      currentRow: null,
      gyShow: false, //供应商弹窗状态
      buyerShow: false, //采购员弹窗状态
			addProShow: false, //商品信息弹窗
      proData: [],
      writOradd: 0, //0新增，1编辑
			islook: false
    };
  },
  mounted(){
    this.getpeople()
    this.bumenList()
    this.gongyingList()
    console.log(this.$route.params)
    if(this.$route.params.options){
      this.tempData = JSON.parse(this.$route.params.options)
      console.trace('tempData:',this.tempData)
      this.proData = this.tempData.listsCommodity
      this.writOradd = 1
    }else{
      this.writOradd = 0
    }
		if(this.$route.params.look){
			this.islook = true
		}else{
			this.islook = false
		}
  },
  methods: {
		saveOrder(){
			this.$router.go(-1)
		},
    // 人员列表
    getpeople(id){
      console.log('id:',id)
      getUser({departments: id}).then(res => {
        console.log(res)
        this.peopleData = res.data.list
      })
    },
    // 部门列表
    bumenList(){
      getBumen({}).then(res => {
        console.log(res)
        res.data.map(item => {
					item.value = item.departments
					return item
				})
				this.ifydata = [this.ifydata[0],...res.data]
      })
    },
    // 供应商列表
    gongyingList(){
      getGongying({}).then(res => {
        console.log(res)
        this.gongying = res.data
      })
    },
    // 选择人员分类
    handleSelece(index){
			console.log(index)
			console.log('ifydata:',this.ifydata[index])
			const navindex = this.ifydata[index].value ? this.ifydata[index].value : null
			this.getpeople(navindex)
    },
    goPrev(page) {
      console.log(page);
    },
    goNext(page) {
      console.log(page);
    },
		// 确认选择供应商
    handleGongying(val) {
      console.log(val);
      this.currentRow = val.name;
    },
		// 选择供应商
    checkGy() {
      this.gyShow = true;
    },
		// 选择采购员
    checkBuyer() {
      this.buyerShow = true;
    },
    // 选择操作人员
    handlePeople(row){
      console.log(row)
      this.tempData.operator = row.username
      console.log(this.tempData.buyer)
			this.buyerShow = false
		},
		// 删除对应商品数据
		deleteRow(value,index){
			console.log(index)
			this.proData.splice(index,1)
		},
		// 取消新增
		nosaveOrder(){
			console.log('取消')
			this.$router.go(-1)
		}
  }
};
</script>
<style lang="scss" scoped>
.popup {
  padding: 0 20px;
}
.product{
  display: flex;
  .pro-l{
    width: 200px;
  }
  .pro-r{
    flex: 1;
    overflow: hidden;
    /deep/.el-table--enable-row-hover .el-table__body tr:hover>td {
      background-color: rgba(24,160,94,.2);
    }
    /deep/.el-table tr{
      cursor: pointer;
    }
    /deep/.el-table__body tr.current-row>td {
      background-color: rgba(24,160,94,.4);
    }
  }
}
.files {
  display: flex;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  margin-top: 20px;
  overflow: hidden;
  padding: 20px;
}
.files-btm .btn-prev:after {
  content: "上一页";
}
.files-btm .btn-next:before {
  content: "下一页";
}
.files-btm .btn-prev,
.files-btm .btn-next {
  width: 65px;
}
.files-left {
	width: 160px;
	margin-right: 20px;
	/deep/.el-menu{
		border-right: none;
	}
	/deep/.el-menu-item{
		height: 35px;
		line-height: 35px;
		margin-bottom: 8px;
	}
	/deep/.el-menu-item.is-active{
		color: #fff;
		border-radius: 5px;
		background: rgba(24,160,94,.8);
	}
}
.files-right {
  flex: 1;
  overflow: hidden;
}
.files-btm {
  background: rgba(255, 255, 255, 1);
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  // margin-top: 20px;
  overflow: hidden;
  &-title {
    display: flex;
    align-items: center;
    height: 45px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: #ffffff;
    > p {
      text-align: center;
      font-size: 16px;
      color: #333;
    }
  }
  .addDate {
    margin: 20px 32px 10px 32px;
    height: 32px;
    border-radius: 3px;
    text-align: center;
    line-height: 32px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    border: 1px dashed rgba(0, 0, 0, 0.3);
  }
  .el-button--text {
    margin: 0 15px;
  }
}
.avatar{
	width: 30px;
	height: 30px;
}
.zd3-btm {
  background: rgba(255, 255, 255, 1);
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  margin-top: 10px;
  overflow: hidden;
  &-title {
    display: flex;
    align-items: center;
    height: 70px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: #ffffff;
    > p {
      text-align: center;
      font-size: 16px;
      color: #333;
    }
  }
  .addDate {
    margin: 20px 32px 10px 32px;
    height: 32px;
    border-radius: 3px;
    text-align: center;
    line-height: 32px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    border: 1px dashed rgba(0, 0, 0, 0.3);
  }
  .el-button--text {
    margin: 0 15px;
  }
}
.inps {
  width: 95%;
  height: 32px;
  line-height: 32px;
  padding-left: 10px;
  background: none;
  border: none;
  color: rgba(0, 0, 0, 0.8);
}
.inps-active {
  width: 95%;
  height: 32px;
  line-height: 32px;
  padding-left: 10px;
  background: rgba(24,160,94,.2);
  border: none;
  color: rgba(0, 0, 0, 0.8);
}
.change {
  display: flex;
  flex-wrap: wrap;
  background: #fff;
  border-radius: 8px;
  padding: 20px;
  > p {
    width: 25%;
    font-size: 14px;
    display: flex;
    align-items: center;
    color: #333;
    /deep/.el-input__inner {
      // width: inherit;
      background: none;
      height: 32px;
      // line-height: 32px;
      color: #333;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding: 0 25px;
    }
    /deep/.el-input__icon {
      line-height: 32px;
    }
    .userselect {
      // max-width: 250px;
      flex: 1;
    }

    > span {
      display: block;
      width: 120px;
      text-align: right;
      padding-right: 15px;
    }
    > input {
      width: inherit;
      flex: 1;
      height: 32px;
      border-radius: 3px;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding-left: 10px;
      color: #333;
    }
  }
}
.submits{
	display: flex;
	padding: 15px 20px;
	justify-content: flex-end;
	align-items: center;
	>div{
		width: 80px;
		height: 32px;
		text-align: center;
		line-height: 32px;
		color: #fff;
		font-size: 14px;
		border-radius: 4px;
		margin-left: 30px;
		cursor: pointer;
	}
	.save{
		background: #2196F3;
	}
	.nosave{
		background: #999;
	}
}
@media screen and (max-width: 1400px) {
  .change > p {
    width: 33%;
  }
}
</style>